package homework.service;

import java.util.ArrayList;
import java.util.List;

import homework.entity.*;
import homework.view.QueryFrame;
import homework.dao.*;

public class Usermanage {
	private List<User> ulist;
	private UserDaoImpl userDaoImpl=new UserDaoImpl();
	
	public User login(String username,char[] passwordString,String type) {
		User user=null;
		ulist= userDaoImpl.getUlist();
		for(User u:ulist) {
			if(u.getUsername().equals(username)&&
					u.getPassword().equals(new String(passwordString))&&
					u.getType().equals(type)) {
				user = u;
				
			}
		}
		
		return user;
	}
	public void register(User u) {

		userDaoImpl.addUser(u);
	}
	
	public int packagecreate(String username,String id, String kilometer,String weigth,String type,String origin,String recipient,String destination) {

		User user= userDaoImpl.printUser(username);
		Mypackage mypackage = new Mypackage(id,Double.valueOf(kilometer) ,Double.valueOf(weigth),Integer.valueOf(type),origin,username, recipient,destination);
		user.getList().add(mypackage);
		userDaoImpl.changeUser(user);
		return 1;
	}
	
	public int packageadd(String username,String id,String logisticslist){
		User user= userDaoImpl.printUser(username);
		
		for(Mypackage my: user.getList()) {
			if(my.getId().equals(id)) {
				my.getLogisticslist().add(logisticslist);
			}
		}
		userDaoImpl.changeUser(user);
		return 1;
	
	}

	

}
